import BaseHTTPServer


class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
     def do_HEAD(s):
         s.send_response(200)
         s.send_header("Content-type", "text/html")
         s.end_headers()
     def do_POST(s):
         print "Content-Length is ", s.headers.get('Content-Length')
         contentLength = int(s.headers.get('Content-Length'))

         print "\nReceived POST for path ", s.path
         print "From client : ", s.client_address
         print "DATA--START\n"
         print s.rfile.read(contentLength)
         print "DATA--END\n"

         s.send_response(201)
         s.send_header("Location", "http://172.1.1.1.1/boards/45")
         s.end_headers()
         s.wfile.write("http://172.1.1.1.1./boards/45")
         s.wfile.write("le lapin mange  une carotte")
     def do_GET(s):
         """Respond to a GET request."""
         s.send_response(200)
         s.send_header("Content-type", "xml")
         s.end_headers()
         s.wfile.write(
"""<?xml version="1.0"?>
<goimerir xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="VersionUsers" version="0.1">
<users>
<user name="pgrabalosa" fullname="pierre" url="http://127.16.7.11/users/45"/>
<user name="pgrabalosa1" fullname="pierre1" url="http://127.16.7.11/users/65"/>
</users>
</goimerir>""")


def run(server_class=BaseHTTPServer.HTTPServer,
        handler_class=BaseHTTPServer.BaseHTTPRequestHandler):
    server_address = ('', 8080)
    httpd = server_class(server_address, handler_class)
    httpd.serve_forever()


run(handler_class = MyHandler)
